/*
 * Title: 移动盒子（Boxes in a Line）
 * Author: Yuanshun L
 * Created : 23-otc-2021
 */


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

#define MAXN 1000001
int rgt[MAXN],lft[MAXN];

void init_boxes(int n){
    rgt[0] = 1; lft[0] = n;
    for(int i=1;i<=n;i++){
        rgt[i] = (i+1)%(n+1);
        lft[i] = i-1;
    }
}

void link(int l,int r){
    lft[r] = l; rgt[l] = r;
}

long long odd_index_sum(int flag){
    int* pointer;
    if(flag)
        pointer = lft;
    else
        pointer = rgt;

    int index=0;
    long long sum=0;
    do{
        index = pointer[index];
        if(index)
            sum += index;
        else
            break;
        index = pointer[index];
    }
    while(index);
    return sum;
}

void print(bool flag){
    int *pointer;
    pointer = flag ? lft:rgt;
    int j=0;
    int index = 0;
    index = pointer[index];
    while(index){
        j++;
        cout << index <<" ";
        index = pointer[index];
        if(j>30) break; // 防止无限循环
    }
    cout<<endl;
}

int main(){

    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);

    int n,m,cmd,pos1=0,pos2=0;
    bool flag;
    int rnd = 0;
    while(cin>>n>>m){
        init_boxes(n);
        flag = false;
        for(int i=1;i<=m;i++){
            cin >> cmd;
            if(cmd!=4){
                cin>> pos1 >> pos2;
            }
            if(cmd==1 || cmd==2){
                cmd = flag ? 3-cmd : cmd;
            }

            // 执行命令
            if(cmd==1){
                if(rgt[pos1]!=pos2){
                    link(lft[pos1],rgt[pos1]);
                    link(lft[pos2],pos1);
                    link(pos1,pos2);
                }
            }
            else if(cmd==2){
                if(lft[pos1]!=pos2){
                    link(lft[pos1],rgt[pos1]);
                    link(pos1,rgt[pos2]);
                    link(pos2,pos1);
                }
            }
            else if(cmd==3){
                int pos1_l=lft[pos1],pos1_r=rgt[pos1];
                int pos2_l=lft[pos2],pos2_r=rgt[pos2];

                link(pos1_l,pos2);
                link(pos1,pos2_r);
                // 如果pos1在pos2的左边
                if(pos1_r==pos2_l){
                    link(pos2,pos1);
                }
                // 如果pos1在pos2的右边
                else if(pos1_r==pos2_l){
                    link(pos1,pos2);
                }
                // pos1与pos2不相邻
                else{
                    link(pos2,pos1_r);
                    link(pos2_l,pos1);
                }
            }
            else{
                flag = !flag;
            }
//            cout<<flag<<endl; // 检查程序
//            print(flag); // 检查程序
        }
//        print(flag); // 检查程序
        cout<<"Case "<< ++rnd <<": " << odd_index_sum(flag) <<endl;
    }



    return 0;
}
